//
//  MyNotificationCenter.m
//  RunLoopDemo
//
//  Created by zhangjikuan on 2021/6/4.
//  Copyright © 2021 hsgd. All rights reserved.
//

#import "MyNotificationCenter.h"

@interface MyNotification ()
@property (readwrite, copy) MYNotifcationName name;
@property (nullable, readwrite, retain) id object;
@property (nullable, readwrite, copy) NSDictionary *userInfo;

@end


@implementation MyNotification

- (instancetype)initWithName:(MYNotifcationName)name object:(nullable id)object userInfo:(nullable NSDictionary *)userInfo;
{
    self = [super init];
    if (self) {
        _name = name;
        _object = object;
        _userInfo = userInfo;
    }
    return self;
}

- (instancetype)initWithCoder:(NSCoder *)coder {
    if (self=[super init]) {
        self.name = [coder decodeObjectForKey:@"name"];
        self.object = [coder decodeObjectForKey:@"objcet"];
        self.userInfo = [coder decodeObjectForKey:@"userInfo"];
    }
    return self;
}

- (void)encodeWithCoder:(NSCoder *)coder {
    [coder encodeObject:self.name forKey:@"name"];
    [coder encodeObject:self.object forKey:@"object"];
    [coder encodeObject:self.userInfo forKey:@"userInfo"];

}

- (id)copyWithZone:(NSZone *)zone {
    MyNotification *notification = [[[self class] allocWithZone:zone] init];
    notification.name = self.name;
    notification.object = self.object;
    notification.userInfo = self.userInfo;
    
    return notification;
}

@end

@implementation MyNotification(MyNotificationCreation)

+ (instancetype)notificationWithName:(NSNotificationName)aName object:(nullable id)anObject {
    return [[MyNotification alloc] initWithName:aName object:anObject userInfo:nil];;
}
+ (instancetype)notificationWithName:(NSNotificationName)aName object:(nullable id)anObject userInfo:(nullable NSDictionary *)aUserInfo {
    return [[MyNotification alloc] initWithName:aName object:anObject userInfo:aUserInfo];
}


@end

@implementation MyNotificationCenter

@end
